<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<%@taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt"%>
<%@ taglib prefix="fn" uri="http://java.sun.com/jsp/jstl/functions" %>
<%@ include file="/WEB-INF/component/commonTagLib.jsp"%>
<!DOCTYPE html>
<html>
<head>
    <title><spring:message code="message.lable.hospinfoSTDsee"/></title>
    <%@ include file="/WEB-INF/component/commonCSS.jsp" %>
    <!--[if lt IE 9]>
        <script src="${ctx}/lib/js/html5shiv.min.js"></script>
        <script src="${ctx}/lib/js/respond.min.js"></script>
    <![endif]-->
</head>
<body class="skin-blue-light sidebar-mini fixed skin-blue-light-frame">
                            
    <section class="content-header">
        <h1><spring:message code="message.lable.hospinfoSTDsee"/></h1>
        <ol class="breadcrumb">
            <li><a href="${ctx}/home.jsp"><i class="fa fa-home"></i><spring:message code="message.lable.first"/></a></li>
            <li class="active"><a href="#">目录管理</a></li>
            <li class="active"><a href="#">配送关系管理</a></li>
            <li class="active"><a href="#">设置配送关系</a></li>
        </ol>
    </section>
    
    <section class="content">
        <div class=" box box-success">
            <div class="box-body">
             <form action="${ctx}/stdHospInfo/exportExcel.html" id="exportExcel" method="post">
            <input id="fileName" name="fileName" type="hidden" value="<spring:message code="message.lable.hospInfoxls"/>" />
                <div class="input">
                <div class="textalign1"><spring:message code="message.listForm.yiLiaoJiGouMingCheng"/>：</div>
                    <div class="boxinput">
                        <input type="text" class="textinput" id="hospName" name="hospName" placeholder="<spring:message code="message.listForm.yiLiaoJiGouMingCheng"/>" maxlength="200"/>
                    </div>
                    <div class="textalign"><spring:message code="message.listForm.yiLiaoJiGouBianMa"/>：</div>
                    <div class="boxinput">
                        <input type="text" class="textinput" id="hospCode"  name="hospCode" placeholder="<spring:message code="message.listForm.yiLiaoJiGouBianMa"/>" maxlength="100"/>
                    </div>
                    
                    <div class="textalign"><spring:message code="message.listForm.yiLiaoJiGouFenLei"/>：</div>
                    <div class="boxinput">
                         <select class="textinput"  id="hospClassify"  name="hospClassify"></select>
                    </div>
                </div>
                <div class="input" style="margin-top:-5px">
                    <div class="textalign1"><spring:message code="message.listForm.suoShuDiQu"/>：</div>
                    <div class="boxinput">
                       <table style="width:100%;">
                           <tr>
                              <td style="width:33%">
                                <select class="textinput" id="area1" disabled="disabled" name="area1"> 
                            <option value="${sysProvince}">${sysProvinceName}</option>
                        </select>
                              </td>
                              <td style="width:33%">   
                                <select class="textinput" id="area2" name="area2" ></select>
                                </td>
                              <td style="width:33%">
                                <select class="textinput" id="area3" name="area3" ></select>
                              </td>
                           </tr> 
                        </table>
                    </div>
                    <div class="textalign">医疗机构等级：</div>
                    <div class="boxinput">
                          <select class="textinput"  id="hospLevel"  name="hospLevel"></select>
                    </div>
                    <div class="textalign" >
                          <button id="selectHospinfo" type="button" class="btn btn-success btn-sm" onclick="search();"><spring:message code="message.button.seachSpacing"/></button>
                    </div> 
                </div>
            </form>
            </div>
          </div>
        <table class="jqgrid" id="gridlist"></table>
        <div id="gridpage"></div>
        
        <div class=" box box-warning bottongroup">
             <a href="${ctx }/baseDel/toDelProdCompList.html" class="btn btn-default btn-sm">返 回</a>
        </div>
  
    </section>
    
    <%@ include file="/WEB-INF/component/commonJS.jsp"%>
    
    <script type="text/javascript">
    
    //绑定回车
    $('#hospCode,#hospName,#hospClassify,#area1,#area2,#area3,#status').bind('keydown', function(event) {
        if (event.keyCode == "13") {        //13 位电脑上回车键的位置代码
            $('#selectHospinfo').click();
        }
    }); 
  
    $("#hospName").focus();//加载页面光标在第一个查询框内
    
        function batchChangeStatus(status) {
            var msg = "";
            var url = ""; 
            if (status == 1){
                msg = "<spring:message code="message.button.start"/>";
                url = "${ctx}/stdHospInfo/disable.html";
            } else if (status == 0){
                msg = "<spring:message code="message.button.stop"/>";
                url = "${ctx}/stdHospInfo/enable.html";
            }
            var rowIds = $("#gridlist").jqGrid("getGridParam", "selarrrow") || [];
            if (rowIds.length <= 0) {
                $.alert("<spring:message code="message.lable.pleaseSelect"/>"+msg+"<spring:message code="message.listForm.yiLiaoJiGou"/><spring:message code="message.yanZheng.ganTanHao"/>", "warn");
                return;
            }
            
            var str = "";
            var names = "";
            var count = 0;
                for (var i = 0;i < rowIds.length; i++){
                    var rowdata = $("#gridlist").jqGrid('getRowData', rowIds[i]);
                    if (status == 1){
                        if (rowdata.status == "<spring:message code="message.button.stop"/>"){
                            names += rowdata.hospName+",";
                            str += rowIds[i]+",";
                            count++;
                        }
                    } else {
                        if (rowdata.status == "<spring:message code="message.button.start"/>"){
                            names += rowdata.hospName+",";
                            str += rowIds[i]+",";
                            count++;
                        }
                    }
                }
                if (names != ""){
                    names = names.substring(0,names.length-1);
                } else {
                    $.alert("<spring:message code="message.lable.ninXuanZe"/><spring:message code="message.listForm.yiLiaoJiGou"/><spring:message code="message.lable.yiJingShi"/>"+msg+"<spring:message code="message.lable.zhuangTaiGTH"/>", "warn");
                    return;
                }
            
                if(names.length>69){
                	names=names.substring(0,66)+"...";
                }
                
                  $.HN.message.confirm('<spring:message code="message.lable.OKYES"/>'+msg+'<spring:message code="message.lable.yiXia"/><spring:message code="message.listForm.yiLiaoJiGou"/><spring:message code="message.lable.ma"/><br/>'+names, '', '').on(function (e) {
                if (e) {
                    if (str.length > 0){
                        str = str.substring(0,str.length-1);
                    }
                    var list = [];
                    for (var i=0; i<rowIds.length; i++) {
                        rowId = rowIds[i];
                        list.push(rowId);
                    }
                    $.post(url, {
                        "array" : json.jsonToString(list),"status":status
                    }, function(result) {
                        if (result.success) {
                            $.alert("<spring:message code="message.HN.alert.chengGong"/>"+msg+''+count+"<spring:message code="message.lable.tiao"/><spring:message code="message.listForm.yiLiaoJiGou"/><spring:message code="message.yanZheng.ganTanHao"/>", "success");
                            var curpage = $("#gridlist").jqGrid('getGridParam', 'page');
                            search(curpage);
                            
                        } else {
                            $.alert("<spring:message code="message.HN.alert.baoCunBai"/>","error");
                        }
                    }, "json");
                }
            });
        }
        
        function search(page) {
            var hospCode = $("#hospCode").val();
            var hospName = $("#hospName").val();
            var hospClassify = $("#hospClassify").val();
            var hospLevel = $("#hospLevel").val();
            var areaId = $("#area3").val();
            var fatherId = "";
            if (areaId.length < 1){
            	fatherId = $("#area2").val();
            }

            $("#gridlist").jqGrid('setGridParam',{  
                datatype:'json',
                postData:{"hospCode":hospCode, "hospName":hospName, "projId":"${param.projId}", "hospClassify": hospClassify,"hospLevel":hospLevel,"fatherId":fatherId, "projId":"${param.projId}","goodsCode":"${param.goodsCode}"},
                page : (page || 1)
            }).trigger("reloadGrid"); //重新载入  
        }
    
        $(function () {
            $("#gridlist").jqGrid({
                url: "${ctx}/baseDel/getDelByHospData.html",
                mtype: "post",
                postData:{"projId":"${param.projId}","goodsCode":"${param.goodsCode}"},
                datatype: "json",
                autowidth: true,
                height: 270,
                colNames: [
                    '<spring:message code="message.jqGrid.cz"/>',
                    '<spring:message code="message.listForm.yiLiaoJiGouBianMa"/>', 
                    '<spring:message code="message.listForm.yiLiaoJiGouMingCheng"/>', 
                    '<spring:message code="message.listForm.yiLiaoJiGouFenLei"/>', 
                    '<spring:message code="message.listForm.suoShuDiQu"/>', 
                    '<spring:message code="message.listForm.yiLiaoJiGouDengJi"/>'
                ],
                colModel: [
                    { name: 'operate', width: 20, align:"center", sortable: false,
                        formatter : function(val, opts, rowdata) {
                        	var str = "<a href='${ctx}/baseDel/toSetDelByHospWithDelcompList.html?hospCode=" + rowdata.hosp_code + "&compCode=${param.compCode}' style='background:url(${ctx}/lib/img/icon/icon.png) no-repeat -120px 0px' class='opIcon' title='设置配送企业'></a>";
                        return str;
                    }},
                    { name: 'hosp_code', width: 100, align:"center", sortable: false},
                    { name: 'hosp_name', width: 160, align:"left", sortable: false },
                    { name: 'hospClassify', width: 120, align:"left", sortable: false},
                    { name: 'area_name', width: 110, align:"center", sortable: false},
                    { name: 'hospLevel', width: 100, align:"center", sortable: false}
                    
                ],
                rowNum: 20,
                rowList: [10, 20, 50,100],
                rownumbers: true,
                pager: "#gridpage",
                multiselect: false, 
                viewrecords: true,
                caption: "<spring:message code="message.list.hospinfoStdlist"/>---${compName}",
                gridComplete:function(){
                    //序号列宽度自适应（参数为jqgridID）
                    autoRNWidth("gridlist");
                    //数据只有一条时默认选中（参数为jqgridID）
                    selectByOneData("gridlist");
                },
                
                jsonReader: {
                    id: "hospId",
                    repeatitems: false
                }
            });
            
            $("#gridlist").jqGrid('navGrid', '#gridpage', { add: false, edit: false, del: false, search: false, refresh: false });
            
            $("#area2").HNSelect({
                url: "${ctx}/selectController/getArea.html", 
                data: { ID: '${sysProvince}' },
                defaultText: "<option value=''><spring:message code="message.select.option"/></option>",
                defaultselect: "",
                func: function () {
                    $("#area3").HNSelect({
                        parent_selector: "#area2", 
                        url: "${ctx}/selectController/getArea.html", 
                        dataid: "ID", 
                        defaultText: "<option value=''><spring:message code="message.select.option"/></option>",
                        defaultselect: ""
                    });
                }
            });
            $("#hospClassify").HNSelect({
                url: "${ctx}/selectController/getArchiveType.html", 
                data: { classifyCode: "113" },
                defaultText: "<option value=''><spring:message code="message.select.option"/></option>",
                defaultselect: "",
            });
            
            $("#hospLevel").HNSelect({
                url: "${ctx}/selectController/getArchiveType.html", 
                data: { classifyCode: "002" },
                defaultText: "<option value=''><spring:message code="message.select.option"/></option>",
                defaultselect: "",
            });

            $(window).trigger("resize");
        });
        
    </script>
</body>
</html>